package com.tencent.cloud.iov.block;

import android.annotation.SuppressLint;
import android.support.annotation.NonNull;
import android.view.View;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 组合视图
 *
 * 用于保存组合区块布局生成的视图，可通过 {@link Iterable} 方式进行遍历
 *
 * @author showxiao
 * @date 2018/4/18
 */

@SuppressLint("ViewConstructor")
public final class CompositeBlockView extends View implements Iterable<View> {

    private List<View> mViewList = new ArrayList<>();

    public CompositeBlockView() {
        super(BlockManager.getContext());
    }

    public void addView(View view) {
        if (view == null) {
            return;
        }

        if (mViewList.contains(view)) {
            mViewList.remove(view);
        }
        mViewList.add(view);
    }

    public void removeView(View view) {
        if (view == null) {
            return;
        }

        mViewList.remove(view);
    }

    @NonNull
    @Override
    public Iterator<View> iterator() {
        return mViewList.iterator();
    }
}
